/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.usc.cs523.client;

import com.jme3.math.Vector3f;
import com.jme3.network.serializing.Serializer;
import edu.usc.cs523.settings.Global;
import edu.usc.cs523.util.CeceMessage;

/**
 *
 * @author haoxu
 */
public class MessageFactory {

    static MessageFactory messageFactory;

    private MessageFactory() {
    }

    public static MessageFactory getInstance() {
        if (messageFactory == null) {
            messageFactory = new MessageFactory();
        }
        return messageFactory;
    }

    public CeceMessage getMoveLeftMessage(int id, boolean reliable, Vector3f curr, Vector3f dir) {
        CeceMessage message = new CeceMessage();
        message.setAction(Global.ACTION_ACTION);
        message.setMessage(Global.MOVE_LEFT);
        message.setId(id);
        message.setReliable(reliable);
        message.setX(curr.x);
        message.setY(curr.y);
        message.setZ(curr.z);
        return message;
    }

    public CeceMessage getMoveRightMessage(int id, boolean reliable, Vector3f curr, Vector3f dir) {
        CeceMessage message = new CeceMessage();
        message.setAction(Global.ACTION_ACTION);
        message.setMessage(Global.MOVE_RIGHT);
        message.setId(id);
        message.setReliable(reliable);
        message.setX(curr.x);
        message.setY(curr.y);
        message.setZ(curr.z);
        message.setA(dir.x);
        message.setB(dir.y);
        message.setC(dir.z);
        return message;
    }

    public CeceMessage getMoveForwardMessage(int id, boolean reliable, Vector3f curr, Vector3f dir) {
        CeceMessage message = new CeceMessage();
        message.setAction(Global.ACTION_ACTION);
        message.setMessage(Global.MOVE_FORWARD);
        message.setId(id);
        message.setReliable(reliable);
        message.setX(curr.x);
        message.setY(curr.y);
        message.setZ(curr.z);
        message.setA(dir.x);
        message.setB(dir.y);
        message.setC(dir.z);
        return message;
    }

    public CeceMessage getMoveBackMessage(int id, boolean reliable, Vector3f curr, Vector3f dir) {
        CeceMessage message = new CeceMessage();
        message.setAction(Global.ACTION_ACTION);
        message.setMessage(Global.MOVE_BACK);
        message.setId(id);
        message.setReliable(reliable);
        message.setX(curr.x);
        message.setY(curr.y);
        message.setZ(curr.z);
        message.setA(dir.x);
        message.setB(dir.y);
        message.setC(dir.z);
        return message;
    }

    public CeceMessage getJumpMessage(int id, boolean reliable, Vector3f curr) {
        CeceMessage message = new CeceMessage();
        message.setAction(Global.ACTION_ACTION);
        message.setMessage(Global.JUMP);
        message.setId(id);
        message.setReliable(reliable);
        message.setX(curr.x);
        message.setY(curr.y);
        message.setZ(curr.z);
        return message;
    }

    public CeceMessage getConnectMessage(int id, int model) {
        CeceMessage message = new CeceMessage();
        message.setAction(Global.ACTION_CONNECT);
        message.setMessage(model);
        message.setId(id);
        message.setReliable(true);
        return message;
    }

    public CeceMessage getDisconnectMessage(int id) {
        CeceMessage message = new CeceMessage();
        message.setAction(Global.ACTION_DISCONNECT);
        message.setMessage('0');
        message.setId(id);
        message.setReliable(true);
        return message;
    }

    public CeceMessage getStatusMessage(Vector3f direction, Vector3f position, int id, int model_num) {
        CeceMessage message = new CeceMessage();
        message.setAction(Global.ACTION_STATUS);
        message.setMessage(model_num);
        message.setId(id);
        message.setReliable(true);
        message.setPosition(position);
        message.setDirection(direction);
        return message;
    }

    public CeceMessage createMoveMessage(Vector3f position, Vector3f direction, int id, boolean reliablt) {
        CeceMessage message = new CeceMessage();
        message.setReliable(reliablt);
        message.setAction(Global.ACTION_ACTION);
        message.setMessage(Global.MOVE_MOVE);
        message.setId(id);
        message.setPosition(position);
        message.setDirection(direction);
        return message;
    }

    public CeceMessage getShotMessage(int shooter, int target, int damage) {
        CeceMessage message = new CeceMessage();
        message.setReliable(true);
        message.setAction(Global.ACTION_CHANGE);
        message.setMessage(damage);
        message.setId(shooter);
        message.setTarget(target);
        return message;
    }

    public CeceMessage getMoveDirectionMessage(int id, boolean reliable, Vector3f curr, Vector3f dir) {
        CeceMessage message = new CeceMessage();
        message.setAction(Global.ACTION_ACTION);
        message.setMessage(Global.MOVE_DIRECTION);
        message.setId(id);
        message.setReliable(reliable);
        message.setX(curr.x);
        message.setY(curr.y);
        message.setZ(curr.z);
        message.setA(dir.x);
        message.setB(dir.y);
        message.setC(dir.z);
        return message;
    }
}
